home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / comm / jmtl028c.zip / JTPHONEB.C < prev    next >
C/C++ Source or Header  |  1994-04-07  |  23KB  |  826 lines

  1. #define VERSION "$VER: JTPhone 1.11  "__DATE__" ("__TIME__")"
  2.  
  3. #include <stdio.h>
  4. #include <exec/types.h>
  5. #include <exec/execbase.h>
  6. #include <exec/nodes.h>
  7. #include <exec/lists.h>
  8. #include <exec/devices.h>
  9. #include <exec/io.h>
  10. #include <exec/libraries.h>
  11. #include <proto/exec.h>
  12. #include <utility/hooks.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15.  
  16. #include "xferq/xferq.h"
  17. #include "xferq/xferq_pragmas.h"
  18.  
  19. void AddEntry(struct phoneentry *list, unsigned char *entries);
  20. void SaveList(struct phoneentry *list, unsigned char *entries);
  21. void DeleteEntry(struct phoneentry *list, unsigned char *entries);
  22. void EditEntry(struct phoneentry *list, unsigned char *entries);
  23. void MoveEntry(struct phoneentry *list, unsigned char source, unsigned char dest);
  24. void ReadCache(struct phoneentry *list, unsigned char *entries);
  25. void RangeDelete(struct phoneentry *list, unsigned char start,
  26.          unsigned char number, unsigned char entries);
  27.  
  28. #define MAXENTRIES 120
  29.  
  30. struct Library *XferqBase;
  31.  
  32. void startjam(void)
  33. {
  34.  
  35.    void clrscr();
  36.    int getline(char *string, int length);
  37.    void gotoxy(int x, int y);
  38.    
  39.    char i, j, page, tmp, quit;
  40.  
  41.    char temp[255], source[255];
  42.  
  43.    char *address, *domain;
  44.  
  45.    char *version=VERSION;
  46.  
  47.    struct NetAddress *addr;
  48.  
  49.    FILE *infile;
  50.  
  51.    unsigned char entries, entries2, start, end, entry, entry2;
  52.  
  53.    unsigned char pages = 0, mode=0;
  54.  
  55.    static struct phoneentry {
  56.      char address[40];
  57.      char phone[30];
  58.      char type[10];
  59.      char passwd[20];
  60.      char flags[40];
  61.      char city[30];
  62.      char sysop[40];
  63.    } list[MAXENTRIES+1];
  64.  
  65.    if (!(XferqBase = OpenLibrary("xferq.library", 1)))
  66.    {
  67.         printf("Can't Open Libs:Xferq.library v1.0\n");
  68.         exit (1);
  69.    }
  70.  
  71.    clrscr();
  72.  
  73.    if(infile=fopen("s:JamTool.Phone", "r"))
  74.    {
  75.       printf("Reading s:JamTool.Phone file\n");
  76.  
  77.       entries = 1;
  78.  
  79.       while ((fgets(temp, 253, infile) != NULL) && (entries < MAXENTRIES))
  80.       {
  81.  
  82.         if ((temp[0]=='#') || (temp[0]==';') || (strlen(temp) < 3)) continue;
  83.  
  84.         sscanf(temp, "%s %s %s %s %s %s %s", source, list[entries].phone,
  85.            list[entries].type, list[entries].passwd, list[entries].flags,
  86.            list[entries].city, list[entries].sysop);
  87.  
  88.         if(addr=XfqGetAddressTags(source,NULL,XQ_Mandatory,XQADDR_NODE,
  89.                 XQ_Optional,XQADDR_ANYTHING,TAG_DONE))
  90.         {
  91.            if(address=XfqPutAddressTags(addr, XQ_Mandatory,XQADDR_ANYTHING,
  92.                 XQ_Optional,XQADDR_ANYTHING,TAG_DONE))
  93.            {
  94.               XfqExamObjectTags(addr,XQ_Domain,&domain,TAG_DONE);
  95.               strcpy(list[entries].address, address);
  96.               XfqDropObject(address);
  97.               XfqDropObject(addr);
  98.            }
  99.         }
  100.         else
  101.            strcpy(list[entries].address, source);
  102.  
  103.         for(j=0;j<strlen(list[entries].address);j++)
  104.            list[entries].address[j]=toupper(list[entries].address[j]);
  105.  
  106.         for(j=0;j<strlen(list[entries].type);j++)
  107.            list[entries].type[j]=toupper(list[entries].type[j]);
  108.  
  109.         for(j=0;j<strlen(list[entries].passwd);j++)
  110.            list[entries].passwd[j]=toupper(list[entries].passwd[j]);
  111.  
  112.         entries++;
  113.       }
  114.       fclose(infile);
  115.       if (entries == MAXENTRIES)
  116.          printf("Maximum Number of entries allowed read in!\n");
  117.  
  118.       for(i=1;i<entries-1;i++)
  119.       {
  120.          for(j=entries-1;j>i;j--)
  121.          {
  122.             if (strcmp(list[i].address, list[j].address) > 0)
  123.             {
  124.                printf("Sorting...%c%c%c%c%c%c%c%c%c%c", 8,8,8,8,8,8,8,8,8,8);
  125.                list[0]=list[i];
  126.                list[i]=list[j];
  127.                list[j]=list[0];
  128.         }
  129.      }
  130.       }
  131.  
  132.       printf("%s\n", &version[6]);
  133.       printf("\nPress Return to Continue.\n");
  134.       getline(temp,1);
  135.  
  136.    }
  137.  
  138.  
  139.    page = 0;
  140.    clrscr();
  141.    quit = 0;
  142.  
  143.    do {
  144.  
  145.       gotoxy(1,1);
  146.  
  147.  
  148.       printf("\t\t  JamTool PhoneBook Editor By James McOrmond\n");
  149.       printf("\n\t  Total Number of Entries: %03d of %d\n", entries-1, MAXENTRIES-1);
  150.       gotoxy(47,3);
  151.       printf("Current Page: 00 of 00");
  152.  
  153.       if (entries)
  154.       {
  155.          if (!mode)
  156.          {
  157.             pages = ((entries-1) / 14) + 1;
  158.             if (((pages-1) * 14) == (entries-1)) pages--;
  159.  
  160.             if (page < 0) page = 0;
  161.             if (page >= pages) page = pages - 1;
  162.  
  163.             gotoxy(47,3);
  164.             printf("Current Page: %02d of %02d\n\n", page+1, pages);
  165.             start = page * 14 +1;
  166.             end = page * 14 + 15;
  167.             if (end > entries) end = entries;
  168.             for (i=start;i<end;i++)
  169.             {
  170.                printf(" %3d %-25.25s %-23.23s %-6.6s %-15.15s\n", i, list[i].address,
  171.                   list[i].phone, list[i].type, list[i].passwd);
  172.             }
  173.          }
  174.          else
  175.          {
  176.             pages = ((entries-1) / 5) + 1;
  177.             if (((pages-1) * 5) == (entries-1)) pages++;
  178.             if (page < 0) page = 0;
  179.             if (page >= pages) page = pages - 1;
  180.  
  181.             gotoxy(47,3);
  182.             printf("Current Page: %02d of %02d\n\n", page+1, pages);
  183.             start = page * 5 +1;
  184.             end = page * 5 + 6;
  185.             if (end > entries) end = entries;
  186.             for (i=start;i<end;i++)
  187.             {
  188.                printf(" %3d %-25.25s %-23.23s %-6.6s %-15.15s\n", i, list[i].address,
  189.                   list[i].phone, list[i].type, list[i].passwd);
  190.                printf("     %-25.25s %-23.23s %-25s\n", list[i].sysop,
  191.                   list[i].city, list[i].flags);
  192.             }
  193.  
  194.      }
  195.  
  196.       }
  197.       printf("%c%c", 0x9b, 0x4a);
  198.       gotoxy(1, 20);
  199.       printf("  A)dd  D)elete  E)dit  C)opy  I)nsert  M)ove  S)ave  W)rite & Quit  Q)uit\n");
  200.       printf(" V)iew Mode %d  L)oad Cache  R)ange Delete  SPACE)Next Page  BS)Previous Page\n", mode+1); 
  201.       gotoxy(1, 20);
  202.  
  203.       switch(toupper(getchar()))
  204.       {
  205.          case 'W':
  206.               SaveList(list, &entries);
  207.          case 'Q':
  208.               printf("%c%cAre you sure you wish to Quit? ", 0x9b, 0x4a);
  209.               tmp = toupper(getchar());
  210.               if (tmp == 'Y') quit = 1;
  211.               break;
  212.  
  213.          case ' ':
  214.               page++;
  215.               break;
  216.  
  217.          case 8:
  218.               page--;
  219.               break;
  220.  
  221.          case 'A':
  222.               if (entries < MAXENTRIES)
  223.               {
  224.                  AddEntry(list, &entries);
  225.                  page = pages + 1;
  226.           }
  227.               else
  228.                  putchar(7);
  229.               break;
  230.  
  231.          case 'C':
  232.               if (entries < MAXENTRIES)
  233.               {
  234.                  printf("%c%cWhich Entry do you wish to copy? ", 0x9b, 0x4a);
  235.                  if ((getline(temp, 3)) && (entry=atoi(temp)) && (entry < entries))
  236.                  {
  237.                     printf("\nWhat position do you want to copy \"%s\" to: ", list[entry].address);
  238.                     list[entries]=list[entry];
  239.                     if ((getline(temp, 3)) && (entry2=atoi(temp)) && (entry2 < entries))
  240.                     {
  241.                        if (entry2 != entries) MoveEntry(list, entries, entry2);
  242.                        entries++;
  243.                     }
  244.              }   
  245.               }
  246.               else
  247.                  putchar(7);
  248.                  
  249.               break;
  250.  
  251.          case 'D':
  252.               DeleteEntry(list, &entries);
  253.               break;
  254.  
  255.          case 'E':
  256.               EditEntry(list, &entries);
  257.               break;
  258.  
  259.          case 'I':
  260.               if (entries < MAXENTRIES)
  261.               {
  262.                  entries2 = entries;           
  263.                  AddEntry(list, &entries2);
  264.                  if (entries2 != entries)
  265.                  {
  266.                     gotoxy(1,20);
  267.                     printf("%c%c", 0x9b, 0x4d);
  268.                     gotoxy(1,22);
  269.                     printf("What position do you want to insert \"%s\": ", list[entries].address);
  270.                     if ((getline(temp, 2)) && (entry=atoi(temp)) && (entry < entries))
  271.                     {
  272.                        MoveEntry(list, entries, entry);
  273.                        ++entries;
  274.                     }
  275.                  }
  276.               }                    
  277.               else
  278.                  putchar(7);
  279.               break;
  280.  
  281.          case 'L':
  282.               if (entries < MAXENTRIES)
  283.               {
  284.                  printf("%c%cDo you want to add the contents of the T:Jamtool.cache list ", 0x9b, 0x4a);
  285.                  printf("to this list? ");
  286.                  getline(temp, 1);
  287.                  if (temp[0]='Y')
  288.                  {
  289.                     ReadCache(list, &entries);
  290.                     remove("T:JamTool.Cache");
  291.                     page =pages;
  292.                  }
  293.           }
  294.               else
  295.                  putchar(7);
  296.               break;
  297.                     
  298.          case 'M':
  299.  
  300.               printf("%c%cWhat Entry do you wish to move? ", 0x9b, 0x4a);
  301.               if ((getline(temp, 2)) && (entry=atoi(temp)) && (entry < entries))
  302.               {
  303.                  printf("What position do you want to move \"%s\" to: ", list[entry].address);
  304.                  if ((getline(temp, 2)) && (entry2=atoi(temp)) &&
  305.                     (entry2 < entries) && (entry2 != entry))
  306.                     MoveEntry(list, entry, entry2);
  307.           }                    
  308.               break;
  309.  
  310.          case 'R':
  311.               printf("%c%cRange Delete: Starting Where? ", 0x9b, 0x4a);
  312.               if ((getline(temp, 2)) && (entry=atoi(temp)) && (entry < entries))
  313.               {
  314.                  printf("\n             Ending Where? ");
  315.                  if ((getline(temp, 2)) && (entry2=atoi(temp)) &&
  316.                     (entry2 < entries) && (entry2 != entry))
  317.                  {
  318.                     entries2 = entry2 - entry;
  319.                     printf("\nDelete %d Entries starting at %d: Are You Sure? ",
  320.                              entries2, entry);
  321.                     getline(temp,1);
  322.                     if (temp[0] == 'Y')
  323.                     {
  324.                       RangeDelete(list, entry, entries2, entries);
  325.                       entries = entries - entries2;
  326.                     }
  327.                  }
  328.               }
  329.               break;
  330.  
  331.          case 'S':
  332.               SaveList(list, &entries);
  333.               break;
  334.      
  335.          case 'V':
  336.               mode = 1 - mode;
  337.               for(i=4;i<20;i++)
  338.               {
  339.                 gotoxy(1,i);
  340.                 printf("%c%c", 0x9b, 0x4b);
  341.               }
  342.               break;
  343.  
  344.       }
  345.    } while (!quit);
  346.  
  347.    CloseLibrary(XferqBase);
  348. }
  349.  
  350. void RangeDelete(struct phoneentry *list, unsigned char start,
  351.        unsigned char number, unsigned char entries)
  352. {
  353.    char i;
  354.  
  355.    for (i=start;i+number<entries;i++)
  356.       list[i]=list[i+number];
  357.  
  358. }
  359.  
  360. void MoveEntry(struct phoneentry *list, unsigned char source, unsigned char dest)
  361. {
  362.    int i;
  363.  
  364.  
  365.    list[0] = list[source];
  366.  
  367.    if (source > dest)
  368.    {
  369.       for(i=source;i>dest;i--)
  370.         list[i]=list[i-1];
  371.    }
  372.    else
  373.    {
  374.       for(i=source;i<dest;i++)
  375.         list[i]=list[i+1];
  376.    }
  377.    list[dest]=list[0];
  378. }
  379.  
  380.  
  381. void AddEntry(struct phoneentry *list, unsigned char *entries)
  382. {
  383.    char i;
  384.    char temp[255], source[255];
  385.  
  386.    char *address, *domain;
  387.  
  388.    struct NetAddress *addr;
  389.   
  390.    gotoxy(1,20);
  391.    printf("%c%cEnter Address to Add to Phone Book: ", 0x9b, 0x4a);
  392.    if (getline(source, 40))
  393.    {
  394.       if(addr=XfqGetAddressTags(source,NULL,XQ_Mandatory,XQADDR_NODE,
  395.                 XQ_Optional,XQADDR_ANYTHING,TAG_DONE))
  396.         {
  397.            if(address=XfqPutAddressTags(addr, XQ_Mandatory,XQADDR_ANYTHING,
  398.                 XQ_Optional,XQADDR_ANYTHING,TAG_DONE))
  399.            {
  400.               XfqExamObjectTags(addr,XQ_Domain,&domain,TAG_DONE);
  401.               strcpy(list[*entries].address, address);
  402.               XfqDropObject(address);
  403.               XfqDropObject(addr);
  404.            }
  405.         }
  406.         else
  407.            strcpy(list[*entries].address, source);
  408.  
  409.       for(i=0;i<strlen(list[*entries].address);i++)
  410.          list[*entries].address[i]=toupper(list[*entries].address[i]);
  411.  
  412.       gotoxy(37,20);
  413.       printf("%s\n", list[*entries].address);
  414.       
  415.       printf("Enter Phone Number: ");
  416.       if(getline(list[*entries].phone,30))
  417.       {
  418.           char types[7][6] = {"", "FIDO", "UUCP", "UUCP2", "TERM", "NRC"};
  419.  
  420.           gotoxy(1,22);
  421.           printf("1. FIDO    2. UUCP   3. UUCP2   4. TERM   5. NRC");
  422.           gotoxy(1,20);
  423.           printf("%c%c", 0x9b, 0x4d);
  424.           gotoxy(1,22);
  425.           printf("Enter Type of Call: ");
  426.           list[*entries].type[0]=0;
  427.  
  428.           while(!list[*entries].type[0])
  429.           {
  430.              gotoxy(21,22);
  431.              getline(temp,1);
  432.              if ((atoi(temp) >= 1) && (atoi(temp) <= 5)) 
  433.                 strcpy(list[*entries].type, types[atoi(temp)]);
  434.              else printf("%c", 8);
  435.           }
  436.  
  437.           gotoxy(21,22);
  438.           printf("%s",list[*entries].type);
  439.           gotoxy(1,20);
  440.           printf("%c%c", 0x9b, 0x4d);
  441.           gotoxy(1,22);
  442.           printf("Enter Password: ");
  443.           if (getline(list[*entries].passwd, 20))
  444.           {
  445.              for(i=0;i<strlen(list[*entries].passwd);i++)
  446.                 list[*entries].passwd[i]=toupper(list[*entries].passwd[i]);
  447.  
  448.              gotoxy(1,20);
  449.              printf("%c%c", 0x9b, 0x4d);
  450.              gotoxy(1,22);
  451.              printf("Enter Modem Flags: ");
  452.              if (getline(list[*entries].flags, 40))
  453.              {
  454.                 gotoxy(1,20);
  455.                 printf("%c%c", 0x9b, 0x4d);
  456.                 gotoxy(1,22);
  457.                 printf("Enter City Name: ");
  458.                 if (!getline(list[*entries].city, 30))
  459.                    strcpy(list[*entries].city, "-");
  460.                 gotoxy(1,20);
  461.                 printf("%c%c", 0x9b, 0x4d);
  462.                 gotoxy(1,22);
  463.                 printf("Enter Sysop Name: ");
  464.                 if (!getline(list[*entries].sysop, 40))
  465.                    strcpy(list[*entries].sysop, "-");
  466.  
  467.                 for (i=0;i<strlen(list[*entries].sysop);i++)
  468.                    if (list[*entries].sysop[i]==' ')
  469.                       list[*entries].sysop[i]='_';
  470.  
  471.                 for (i=0;i<strlen(list[*entries].city);i++)
  472.                    if (list[*entries].city[i]==' ')
  473.                       list[*entries].city[i]='_';
  474.  
  475.                 ++*entries;
  476.              }
  477.       }
  478.       }
  479.    }      
  480. }
  481.  
  482. void EditEntry(struct phoneentry *list, unsigned char *entries)
  483. {
  484.    char i,t;
  485.    char temp[255];
  486.  
  487.    char *address, *domain;
  488.  
  489.    struct NetAddress *addr;
  490.  
  491.    int entry;
  492.    char types[7][6] = {"", "FIDO", "UUCP", "UUCP2", "TERM", "NRC"};
  493.  
  494.    printf("%c%cWhich Entry do you wish to Edit? ", 0x9b, 0x4a);
  495.    if ((getline(temp, 2)) && (entry=atoi(temp)) && (entry < *entries))
  496.    {
  497.       printf("\nEnter new address for \"%s\": ", list[entry].address);
  498.       t = strlen(list[entry].address);
  499.  
  500.       if (getline(temp, 30))
  501.       {
  502.         if(addr=XfqGetAddressTags(temp,NULL,XQ_Mandatory,XQADDR_NODE,
  503.                 XQ_Optional,XQADDR_ANYTHING,TAG_DONE))
  504.         {
  505.            if(address=XfqPutAddressTags(addr, XQ_Mandatory,XQADDR_ANYTHING,
  506.                 XQ_Optional,XQADDR_ANYTHING,TAG_DONE))
  507.            {
  508.               XfqExamObjectTags(addr,XQ_Domain,&domain,TAG_DONE);
  509.               strcpy(list[entry].address, address);
  510.               XfqDropObject(address);
  511.               XfqDropObject(addr);
  512.            }
  513.         }
  514.         else
  515.            strcpy(list[entry].address, temp);
  516.  
  517.         for(i=0;i<=strlen(list[entry].address);i++)
  518.            list[entry].address[i]=toupper(list[entry].address[i]);
  519.       }
  520.       gotoxy(27+t, 21);
  521.       printf("%c%c%s", 0x9b, 0x4b, list[entry].address);
  522.  
  523.       printf("\nCurrent phone number is: %s", list[entry].phone);
  524.  
  525.       gotoxy(1,20);
  526.       printf("%c%c", 0x9b, 0x4d);
  527.       gotoxy(1,22);
  528.  
  529.       printf("Enter new phone number: ");
  530.       if (getline(temp, 40))
  531.          strcpy(list[entry].phone, temp);
  532.       gotoxy(25,22);
  533.       printf("%c%c%s", 0x9b, 0x4b, list[entry].phone);
  534.  
  535.       gotoxy(1,20);
  536.       printf("%c%c", 0x9b, 0x4d);
  537.       gotoxy(1,22);
  538.  
  539.       printf("1. FIDO    2. UUCP   3. UUCP2   4. TERM   5. NRC");
  540.       gotoxy(1,20);
  541.       printf("%c%c", 0x9b, 0x4d);
  542.       gotoxy(1,22);
  543.  
  544.       printf("Enter new session type [%s]: ", list[entry].type);
  545.       getline(temp,1);
  546.       gotoxy(28+strlen(list[entry].type), 22);
  547.  
  548.       if ((atoi(temp) >= 1) && (atoi(temp) <= 5))
  549.           strcpy(list[entry].type, types[atoi(temp)]);
  550.  
  551.       printf("%s ", list[entry].type);
  552.  
  553.       gotoxy(1,20);
  554.       printf("%c%c", 0x9b, 0x4d);
  555.       gotoxy(1,22);
  556.  
  557.       printf("Enter new password [%s]: ", list[entry].passwd);
  558.       t=strlen(list[entry].passwd);
  559.       if (getline(temp, 20))
  560.           for(i=0;i<=strlen(temp);i++)
  561.              list[entry].passwd[i]=toupper(temp[i]);
  562.       gotoxy(24+t, 22);
  563.       printf("%c%c%s", 0x9b, 0x4b, list[entry].passwd);
  564.  
  565.       gotoxy(1,20);
  566.       printf("%c%c", 0x9b, 0x4d);
  567.       gotoxy(1,22);
  568.       printf("Current modem flags are: %s", list[entry].flags);
  569.       t=strlen(list[entry].flags);
  570.  
  571.       gotoxy(1,20);
  572.       printf("%c%c", 0x9b, 0x4d);
  573.       gotoxy(1,22);
  574.       printf("Enter new modem Flags: ");
  575.       if (getline(temp, 40))
  576.          strcpy(list[entry].flags, temp);
  577.  
  578.       gotoxy(24, 22);
  579.       printf("%c%c%s", 0x9b, 0x4b, list[entry].flags);
  580.       
  581.       gotoxy(1,20);
  582.       printf("%c%c", 0x9b, 0x4d);
  583.       gotoxy(1,22);
  584.  
  585.       printf("Enter new City [%s]: ", list[entry].city);
  586.       t= strlen(list[entry].city);
  587.  
  588.       if (getline(temp, 30))
  589.       {
  590.          strcpy(list[entry].city, temp);
  591.          for (i=0;i<strlen(temp);i++)
  592.             if (list[entry].city[i]==' ')
  593.                list[entry].city[i]='_';
  594.       }
  595.       gotoxy(20+t,22);
  596.       printf("%c%c%s", 0x9b, 0x4b, list[entry].city);
  597.  
  598.       gotoxy(1,20);
  599.       printf("%c%c", 0x9b, 0x4d);
  600.       gotoxy(1,22);
  601.  
  602.       printf("Enter new Sysop [%s]: ", list[entry].sysop);
  603.       if (getline(temp, 30))
  604.       {
  605.          strcpy(list[entry].sysop, temp);
  606.          for (i=0;i<strlen(temp);i++)
  607.             if (list[entry].sysop[i]==' ')
  608.                list[entry].sysop[i]='_';
  609.       }
  610.    }
  611. }
  612.  
  613. void DeleteEntry(struct phoneentry *list, unsigned char *entries)
  614. {
  615.    int i;
  616.    char temp[255], tmp[255];
  617.  
  618.    printf("%c%cEnter Entry Number to Delete: ", 0x9b, 0x4a);
  619.    if (getline(temp,2))
  620.    {
  621.       printf("\nDelete \"%s\", Are you sure? ", list[atoi(temp)].address);
  622.       getline(tmp,1);
  623.       if (tmp[0] == 'Y')
  624.       {
  625.          for(i=atoi(temp);i<*entries;i++)
  626.             list[i]=list[i+1];
  627.          --*entries;
  628.       }
  629.    }
  630. }
  631.  
  632.  
  633. void SaveList(struct phoneentry *list, unsigned char *entries)
  634. {
  635.    char i;
  636.  
  637.    FILE *outfile;
  638.  
  639.    printf("%c%c", 0x9b, 0x4a);
  640.  
  641.    if(outfile=fopen("s:JamTool.Phone", "w")) {
  642.       printf("Writing s:JamTool.Phone file.  Line: ");
  643.       for (i=1;i<*entries;i++)
  644.       {
  645.          fprintf(outfile, "%s %s %s %s %s %s %s\n", list[i].address, list[i].phone,
  646.             list[i].type, list[i].passwd, list[i].flags, list[i].city, list[i].sysop);
  647.          gotoxy(39,20);
  648.          printf("%02d", i);
  649.       }
  650.       fclose(outfile);
  651.       printf("\n");
  652.    } else
  653.       printf("Error Writing s:JamTool.Phone file!\n"); 
  654. }
  655.  
  656. void ReadCache(struct phoneentry *list, unsigned char *entries)
  657. {
  658.  
  659.    FILE *infile;
  660.  
  661.    char temp[255], source[255];
  662.  
  663.    int j, i, found;
  664.  
  665.    char *address, *domain;
  666.  
  667.    struct NetAddress *addr;
  668.  
  669.    if(infile=fopen("t:JamTool.Cache", "r")) {
  670.       printf("Reading t:JamTool.Cache file");
  671.  
  672.       while ((fgets(temp, 253, infile) != NULL) && (*entries < MAXENTRIES))
  673.       {
  674.  
  675.         if ((temp[0]=='#') || (temp[0]==';') || (strlen(temp) < 3)) continue;
  676.  
  677.         sscanf(temp, "%s %s %s %s %s %s %s", source, list[*entries].phone,
  678.            list[*entries].type, list[*entries].passwd, list[*entries].flags,
  679.            list[*entries].city, list[*entries].sysop);
  680.  
  681.         if(addr=XfqGetAddressTags(source,NULL,XQ_Mandatory,XQADDR_NODE,
  682.                 XQ_Optional,XQADDR_ANYTHING,TAG_DONE))
  683.         {
  684.            if(address=XfqPutAddressTags(addr, XQ_Mandatory,XQADDR_ANYTHING,
  685.                 XQ_Optional,XQADDR_ANYTHING,TAG_DONE))
  686.            {
  687.               XfqExamObjectTags(addr,XQ_Domain,&domain,TAG_DONE);
  688.               strcpy(list[*entries].address, address);
  689.               XfqDropObject(address);
  690.               XfqDropObject(addr);
  691.            }
  692.         }
  693.         else
  694.            strcpy(list[*entries].address, source);
  695.  
  696.         for(j=0;j<strlen(list[*entries].address);j++)
  697.            list[*entries].address[j]=toupper(list[*entries].address[j]);
  698.  
  699.         for(j=0;j<strlen(list[*entries].type);j++)
  700.            list[*entries].type[j]=toupper(list[*entries].type[j]);
  701.  
  702.         for(j=0;j<strlen(list[*entries].passwd);j++)
  703.            list[*entries].passwd[j]=toupper(list[*entries].passwd[j]);
  704.  
  705.         gotoxy(1,20);
  706.         printf("%c%c", 0x9b, 0x4d);
  707.         gotoxy(1,22);
  708.         printf(" %02d %s %s ",*entries, list[*entries].address, list[*entries].sysop);
  709.  
  710.         found=0;
  711.  
  712.         for (i=1;i<*entries;i++)
  713.            if (!strcmp(list[*entries].address, list[i].address))
  714.               found = 1;
  715.  
  716.         if (!found) ++*entries;
  717.  
  718.         printf(" Found: %s", found?"Yes":"No");
  719.  
  720.       }
  721.       fclose(infile);
  722.       if (*entries == MAXENTRIES)
  723.       {
  724.          gotoxy(1,20);
  725.          printf("%c%c", 0x9b, 0x4d);
  726.          gotoxy(1,22);
  727.          printf("Maximum Number of entries allowed read in!\n");
  728.       }
  729.  
  730.       gotoxy(1,20);
  731.       printf("%c%c", 0x9b, 0x4d);
  732.       gotoxy(1,22);
  733.  
  734.       printf("Press Return to Continue.");
  735.       getline(temp,1);
  736.  
  737.    }
  738.    else
  739.    {
  740.       gotoxy(1,20);
  741.       printf("%c%c", 0x9b, 0x4d);
  742.       gotoxy(1,22);
  743.       Printf("Could Not Open T:Jamtool.Cache File!");
  744.  
  745.       gotoxy(1,20);
  746.       printf("%c%c", 0x9b, 0x4d);
  747.       gotoxy(1,22);
  748.       printf("Press Return to Continue.");
  749.       getline(temp,1);
  750.    }
  751. }
  752.  
  753. void clrscr()
  754. {
  755.    printf("%c",12);
  756. }
  757.  
  758.  
  759. void gotoxy(int x, int y)
  760. {
  761.    printf("%c%d;%dH", 0x9b, y, x);
  762. }
  763.  
  764.  
  765. int getline(char *string, int length)
  766. {
  767.    int i=0;
  768.    int ch;
  769.    printf("%c%c", 0x9b, 0x4b);
  770.    while (i < length)
  771.    {
  772.        ch = getchar();
  773.        if (length == 1) ch = toupper(ch);
  774.        if (ch==13)
  775.        {
  776.           string[i]=0;
  777.           return(i);
  778.        }
  779.        if (ch==8)
  780.        {
  781.            if (i)
  782.            {
  783.                i--;
  784.                printf("%c %c", ch, ch);
  785.            }
  786.            else
  787.               printf("%c",7);
  788.        }
  789.        else
  790.        {
  791.            string[i++]=ch;
  792.            printf("%c", ch);
  793.        }
  794.    }
  795.    string[i]=0;
  796.    return (i);
  797. }
  798.  
  799.  
  800. void main(int argc, char **argv)
  801. {
  802.   void startjam(void);
  803.  
  804.   FILE *fp;
  805.   char temp[200];
  806.  
  807.   if (argc>1)
  808.   {
  809.      if (!strcmp(argv[1], "raw"))
  810.      {
  811.         startjam();
  812.         return;
  813.      }
  814.   }
  815.   system("delete >nil: t:jtphone-#?");
  816.   sprintf(temp, "t:jtphone-%p", temp);
  817.   fp = fopen(temp, "w");
  818.   fprintf(fp, "failat 9999\n");
  819.   fprintf(fp, "stack 20000\n");
  820.   fprintf(fp, "%s raw\n", argv[0]);
  821.   fprintf(fp, "endcli\n");
  822.   fclose(fp);
  823.   sprintf(temp, "newshell window=raw:0/0/640/200/JamTool_PhoneBook_Editor/nozoom from \"t:jtphone-%p\"", temp);
  824.   system (temp);
  825. }
  826.